package com.ymh.git.thread.juc;

import java.util.concurrent.ExecutionException;

/**
 * 守护线程
 * Created by aivin on 2018/10/28.
 */
public class DeamonThread {

    private static class UseThread extends Thread {

        public UseThread(String name) {
            super(name);
        }

        @Override
        public void run() {
            try {
                while (!isInterrupted()) { //判断线程是否中断
                    System.out.println(Thread.currentThread().getName() + " I am extends Thread");
                }
            } finally {
                System.out.println("...finally");
            }
        }

    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Thread myThread = new UseThread("deamonThread");
        myThread.setDaemon(true);
        myThread.start();
        Thread.sleep(5);
//        myThread.interrupt();// 中断线程
    }
}
